﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace QLTV.Forms.KeHoach
{
    public partial class frmKeHoach : BaseForm
    {
        public frmKeHoach()
        {
            InitializeComponent();
        }
        public bool isLongPlan { get; set; }
        public frmKeHoach(bool isLong)
        {
            InitializeComponent();
            //Phan biet 2 form ngan han va dai han
            isLongPlan = isLong;
            tblKeHoachTableAdapter.FillByLongPlan(dsLongPlan.tblKeHoach, isLong);
        }


        private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            EditPlan();
        }
        private void EditPlan()
        {
            if (viewKeHoach.FocusedRowHandle > -1)
            {
                frmLongPlanVessel f = new frmLongPlanVessel();
                f.PlanID = (int)viewKeHoach.GetFocusedRowCellValue("Planid");
                f.isNew = false;
                f.ShowDialog();
                tblKeHoachBindingSource.DataSource = tblKeHoachTableAdapter.GetData();
            }
        }
        private void frmKeHoach_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dsLongPlan.tblKeHoach' table. You can move, or remove it, as needed.
            this.tblKeHoachTableAdapter.Fill(this.dsLongPlan.tblKeHoach);

        }

        private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {


        }


        private void barButtonItem3_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (viewKeHoach.FocusedRowHandle > -1)
            {
                if (XtraMessageBox.Show(rm.GetString("sConfirm", myCultureInfo), rm.GetString("sMessageCaption", myCultureInfo), MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.OK)
                {
                    tblKeHoachBindingSource.RemoveCurrent();
                    tblKeHoachBindingSource.EndEdit();
                    tblKeHoachTableAdapter.Update(dsLongPlan.tblKeHoach);
                    alertControl1.Show(this, rm.GetString("sMessageCaption", myCultureInfo), rm.GetString("sMessageSuccess", myCultureInfo));
                    

                }
            }
        }

        private void radPlanType_EditValueChanged(object sender, EventArgs e)
        {
            // switch (((RadioGroup)(sender)).EditValue.ToString())
            if (((RadioGroup)(sender)).EditValue.ToString() == "all")
            {
                tblKeHoachBindingSource.Filter = "";
            }
            else if ((bool)((RadioGroup)(sender)).EditValue)
            {
                tblKeHoachBindingSource.Filter = "isLongPlan=1";

            }
            else
                tblKeHoachBindingSource.Filter = "isLongPlan=0";
        }

        private void viewKeHoach_DoubleClick(object sender, EventArgs e)
        {
            EditPlan();
        }
        //them moi dai hạn
        private void barButtonItem5_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frmLongPlanVessel f = new frmLongPlanVessel();
            f.isNew = true;
            f.PlanID = Convert.ToInt32(tblKeHoachTableAdapter.NextID().ToString());
            f.ShowDialog();
            tblKeHoachBindingSource.DataSource = tblKeHoachTableAdapter.GetData();
        }
        //thêm mới ngắn hạn
        private void barButtonItem6_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

        }
    }
}